#!/usr/bin/env python

import SimpleHTTPServer
import SocketServer
import os

os.system('/bin/echo -n "3" > /sys/class/gpio/export')
os.system('/bin/echo -n "out" > /sys/class/gpio/gpio3/direction')
os.system('/bin/echo -n "0" > /sys/class/gpio/gpio3/value')

class MyRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
    def do_GET(self):
        if self.path == '/on':
            os.system('/bin/echo -n "1" > /sys/class/gpio/gpio3/value')
            self.path = '/on.html'
        if self.path == '/off':
            os.system('/bin/echo -n "0" > /sys/class/gpio/gpio3/value')
            self.path = '/off.html'
        return SimpleHTTPServer.SimpleHTTPRequestHandler.do_GET(self)

Handler = MyRequestHandler
server = SocketServer.TCPServer(('0.0.0.0', 8080), Handler)

server.serve_forever()